<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.ArrayList"%>
<%@page import="board.BoardMyba"%>
<%@page import="board.BoardVo"%>
<%@page import="java.util.Vector"%>
<%@page import="board.Board"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>list.jsp</title>
<style>
#list_serial,#list_irum,#list_jemok,#list_mdate,#list_hit{
	display:inline-block;
	background-color:#bbffcc;
}
.item_serial, .item_irum, .item_jemok, .item_mdate,.item_hit{
	display:inline-block;
}
#list_serial,#list_irum,.item_serial,.item_irum,.item_hit{
	width:80px;
}
#list_jemok,.item_jemok{
	width:200px;
}
#list_mdate, .item_mdate{
	width:140px;
}
#Cnt{
	width:355px;
}
#btnwrite{
	margin-left:515px;
}
#Cnt,#find_div{
	display:inline-block;
}
#list_main{
	width:710px;
	margin:auto;
	margin-top:30px;
}
#btn_page{
	align:center;
}
</style>

<script src = "./board_mybatis/board.js"></script>

</head>
<body>
<jsp:useBean id="boardVo" class="board.BoardVo"/>
<jsp:setProperty property="*" name="boardVo"/>
<%
// 검색어 세션처리
if(request.getMethod().equals("POST")){
	session.setAttribute("find", boardVo.getFind());
	session.setAttribute("nowPage", boardVo.getNowPage());
}else{
	if(session.getAttribute("find") != null){
		boardVo.setFind((String)session.getAttribute("find"));
	}
}
// 페이지 정보 유지
if(request.getParameter("nowPage") == null){
	if(session.getAttribute("nowPage") != null){
		boardVo.setNowPage((Integer)session.getAttribute("nowPage"));
	}
}else{
	session.setAttribute("nowPage", boardVo.getNowPage());
}




//게시판의 종류 선별
String part = (String)session.getAttribute("part");
boardVo.setPart(part);

//////////////////////// Mybatis 형태
BoardMyba mybatis = new BoardMyba();
mybatis.setBoardVo(boardVo);
mybatis.setNowPage(boardVo.getNowPage());
ArrayList<BoardVo> data = mybatis.list();



//////////////////////// 기존 형태
/* Board board = new Board();
board.setVo(boardVo);
board.setNowPage(boardVo.getNowPage());

Vector<BoardVo> v = board.list(); */


%>


<div id='list_main'>
<h1>Community List(<%=part %>)</h1>

<div id='Cnt'>
<label>총게시글수 : <%=data.size()%></label>

<output id='bookCnt'>

</output>
</div>
<div id='find_div'>
	<form name='community_form' method='post'>
	<input type='search' id='find'  name='find' value='<%=boardVo.getFind()%>'>
	<input type='button' id='btnfind' value='검색'>
	<input type='hidden' name='nowPage' value="<%=mybatis.getNowPage()%>">
	</form>
</div>



<div id='list_body'>
	<div id='list_title'>
		<div id='list_serial'>No</div>
		<div id='list_jemok'>제목</div>
		<div id='list_irum'>작성자</div>
		<div id='list_mdate'>작성일</div>
		<div id='list_hit'>조회수</div>
	</div>
	<%
	for(int i=0; i<data.size(); i++){
		BoardVo vo = data.get(i);
	%>
	
	
	<div class='list_item'>
		<div class='item_serial'><%=vo.getSerial()%></div>
		<div class='item_jemok'><a href='#' onclick='view(<%=vo.getSerial()%>.)'><%=vo.getSubject()%></a></div>
		<div class='item_irum'><%=vo.getMid()%></div>
		<div class='item_mdate'><%=vo.getMdate()%></div>
		<div class='item_hit'><%=vo.getHit()%></div>
	</div>
	
<%} %>
</div>
<div id='btn_page'><!-- 페이지 분리 영역 -->
	<%if(mybatis.getNowBlock() > 1){ %>
	<input type='button' value='맨첨' onclick='goPage(1)'>
	<input type='button' value='이전' onclick="goPage(<%=mybatis.getStartPage()-1%>)">
	<%} %>
	[
	<%for(int p=mybatis.getStartPage(); p <= mybatis.getEndPage(); p++){ %>
		<input type='button' value='<%=p%>' onclick ='goPage(<%=p%>)'> 
		
	<% }%>
	]
	<%if(mybatis.getNowBlock() < mybatis.getTotBlock()){ %>
	<input type='button' value='다음' onclick='goPage(<%=mybatis.getEndPage()+1%>)'>
	<input type='button' value='맨끝' onclick='goPage(<%=mybatis.getTotPage()%>)'>
	<%} %>
</div>
<p/>
<input type='button' id='btnwrite' value='글쓰기'>
</div>

<script>init();</script>
</body>
</html>